package com.twu.biblioteca;

import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * Created by icarter on 14-06-02.
 */
public class Book {
    String title;
    String author;
    boolean available;
    int publishYear;

    public Book() {
    }

    public Book(String t, String auth, GregorianCalendar date) {
        title = t;
        author = auth;
        available = true;
        publishYear = date.getInstance().get(Calendar.YEAR);
    }

    public boolean checkoutBook() {
        if (available) {
            available = false;
            System.out.println("Thank you! Enjoy the book.");
            return true;
        }  else {
            System.out.println("That book is not available.");
            return false;
        }
    }

    public boolean returnBook() {
        if (available)  {
            System.out.println("That is not a valid book to return.");
            return false;
        } else {
            available = true;
            System.out.println("Thank you for returning the book.");
            return true;
        }
    }

    public void displayInfo() {
        String output = "title: " + title + "\n";
        output += "by " + author + "\n";
        output += "published on " + publishYear + "\n";
        String availability;
        if (available) {
            output += "Available for checkout.";
        } else {
            output += "Not available for checkout.";
        }
        System.out.println(output);
    }
}
